/*
 * F5.c
 *
 *  Created on: 21/10/2012
 *      Author: Sarah
 */

#include "F5.h"

double F5minX = -5;
double F5maxX = 5;
int F5dimensions = 1000;
int nonSeparableGroupSize=50;
double F5Compute(double* x) {
	int i;
	double result = 0.0;

	double* F5Ovector = createShiftVector(F5dimensions,F5minX,F5maxX);
	double* F5anotherz = malloc(sizeof(double) * F5dimensions);
	double* F5anotherz1 = malloc(sizeof(double) * F5dimensions);
	double* F5anotherz2 = malloc(sizeof(double) * F5dimensions);
	int* Pvector = createPermVector(F5dimensions);
	double *RotMatrix = createRotMatrix1D(nonSeparableGroupSize);


	for (i = 0; i < F5dimensions; i++) {
		F5anotherz[i] = x[i] - F5Ovector[i];
	}

	for (i = 0; i < nonSeparableGroupSize; i++) {
		F5anotherz1[i] = F5anotherz[Pvector[i]];
	}

	for (i = nonSeparableGroupSize; i < F5dimensions; i++) {
		F5anotherz2[i - nonSeparableGroupSize] = F5anotherz[Pvector[i]];
	}

	result = rot_rastrigin(F5anotherz1, nonSeparableGroupSize) * 1.0e6
			+ rastrigin(F5anotherz2, F5dimensions - nonSeparableGroupSize);

	free(F5Ovector);
	free(F5anotherz);
	free(F5anotherz1);
	free(F5anotherz2);
	free(Pvector);

	return (result);
}

int F5GetDimensions() {
	return F5dimensions;
}
double F5GetGetMax() {
	return F5maxX;
}
double F5GetMin() {
	return F5minX;
}
